/*
    自定义多分类语义分割的ncnn部署demo
    主要测试了predict_image

*/

#include "dfc_det.h"

#include <iostream>
#include <vector>
#include "net.h"

int main()
{
    // 注意可执行文件与源文件的相对路径
    std::string param_path{"/home/using/Templates/dfc_ncnn/assets/dfc.ncnn.param"};
    std::string bin_path{"/home/using/Templates/dfc_ncnn/assets/dfc.ncnn.bin"};
    std::vector<int> input_shape{1, 3, 384, 640};
    cv::Mat image = cv::imread("../assets/todetect/ori/7008741.jpg");
    cv::Mat fps_image = cv::imread("../assets/todetect/ori/45.jpg");

    CrackSeg model(param_path, bin_path, input_shape);

    // int det_save = 0;
    // int det_show = 1;
    // int det_fps = 2;
    // int det_cam = 3;
    // int det_test = 4;

    int run_mode = 1;

    if (run_mode == 0)
    {
        // 预测并保存
        model.predict_image("../assets/todetect/ori/7008741.jpg", "../assets/todetect/result/2.jpg");
    }

    else if (run_mode == 1)
    {
        // 预测并显示
        image = model.predict_image(image);
        cv::imshow("test", image);
        cv::waitKey(0);
        cv::destroyWindow("test");
    }
    
    else if (run_mode == 2)
    {
        // 计算fps
        int loops = 100;
        std::cout << "---start to calc fps---" << std::endl;
        double t1 = (double)cv::getTickCount();
        for (int i = 0; i < loops; i++)
        {
            cv::Mat segFrame = model.predict_image(fps_image);
        }
        double t2 = (double)cv::getTickCount();
        // time per pic | ms
        double timepp = (t2 - t1) * 1000 / (cv::getTickFrequency()) / loops;
        std::cout << "time:" << timepp << "ms" << std::endl;
        std::cout << "fps:" << 1000 / timepp << std::endl;
    }
    
    else if (run_mode == 3)
    {
        // 摄像头
        // model.predict_camera();
    }

    else if (run_mode == 4)
    {
    // 测试多线程
#pragma omp parallel
        {
            std::cout << "parallel run!!!\n";
        }
    }
    else
    {
        ;
    }

    return 0;
}